/**
 * Project:   dtu.fmes.googleloon
 * File:      SimulationStateUtils.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      Oct 12, 2013
 */

package dtu.fmes.loon.utils;

import dtu.fmes.loon.model.Simulation;
import dtu.fmes.loon.model.SimulationState;
import dtu.fmes.loon.model.environment.Time;

/**
 * Util class for {@link dtu.fmes.loon.model.SimulationState }.
 * 
 * @author Bartosz Cichecki
 * 
 */
public class SimulationStateUtils {

	public static boolean isDay(SimulationState simulationState) {
		return !isNight(simulationState);
	}

	public static boolean isNight(SimulationState simulationState) {
		Time time = simulationState.getEnvironment().getTime();
		Simulation simulation = simulationState.getSimulation();
		if (time.getNightStartTime() == time.getNightEndTime()) {
			return false;
		}

		long timeOfCycle = simulation.getCurrentTime() % time.getCycleLength();

		if (time.getNightStartTime() < time.getNightEndTime()) {
			return timeOfCycle > time.getNightStartTime() && timeOfCycle < time.getNightEndTime();
		} else {
			return timeOfCycle > time.getNightStartTime() && timeOfCycle < time.getNightEndTime();
		}
	}

	private SimulationStateUtils() {

	}

}
